#ifndef _GUI_H_
#define _GUI_H_

#include "render.h"
#include "sprite.h"
#include "resourcemngr.h"
#include "xml.h"
#include "font.h"
#include <list>
#include <string>

using namespace std;

struct gui_event
{
	string id;
	string data;
};

typedef void (*gui_callback)(void* _cls,gui_event _evnt);

class guimngr;

class gui_element
{
public:
	gui_element(guimngr* _parent,xml_node& _node){m_parent=_parent;m_id=_node.attr_str("id","empty");}
	virtual ~gui_element(){}
	virtual bool intersect(float _x, float _y)=0;
	virtual void draw()=0;
	string get_id(){return m_id;}
protected:
	string m_id;
	guimngr* m_parent;
};

class button: public gui_element
{
public:
	button(guimngr* _parent,xml_node& _node);
	~button();

	bool intersect(float _x, float _y);
	void draw();

private:
	texture* m_texture;
	sprite m_sprite;
	string m_text;
	float m_x;
	float m_y;
	float m_w;
	float m_h;
	float m_text_dx;
	float m_text_dy;
};

class guimngr
{
public:
	guimngr(gui_callback _callback,void* _cls,xml_node& _node);
	~guimngr();

	void set_mouse_pos(float _x, float _y);
	void update();
	void draw();

	font* get_font(){return m_font;}

	resourcemngr* m_resmngr;

private:
	list<gui_element*> m_elements;
	font* m_font;
	float m_mx;
	float m_my;
	gui_callback m_callback;
	void* m_cls;
};

#endif